package com.kaisa.activity.utils;

import com.kaisa.activity.bean.Snap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 123 on 2015/12/17.
 */
public class JsonUtils {
    public static List<Snap> jsonData(String st){
        List<Snap> list = new ArrayList<Snap>();
        try {
            JSONArray jsonArray = new JSONArray(st);
            for (int i = 0; i <jsonArray.length() ; i++) {
                Snap snap = new Snap();
                JSONObject object = jsonArray.getJSONObject(i);
                snap.setLineid(object.getString("lineid"));
                snap.setGroupid(object.getString("groupid"));
                snap.setName(object.getString("name"));
                snap.setPrice(object.getString("price"));
                snap.setNowprice(object.getString("nowprice"));
                snap.setDate(object.getString("date"));
                snap.setNum(object.getString("num"));
                snap.setPic(object.getString("pic"));
                snap.setDeparture(object.getString("departure"));
                list.add(snap);
            }
            return  list;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
}
